{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "433a223e-beef-469b-beca-aec37a2c0e84",
   "metadata": {
    "tags": []
   },
   "source": [
    "执行命令需要在同一行命令中，先source环境名(base,python27,python36,python37,python38,python39,python310,cube-studio)才能pip安装到指定环境，如果不知道有哪些虚拟环境，可以conda info --envs查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d3a6783f-931c-495b-9f44-a8f4ad98da37",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in /root/miniconda3/envs/cube-studio/lib/python3.9/site-packages (2.0.1)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in /root/miniconda3/envs/cube-studio/lib/python3.9/site-packages (from pandas) (2.8.2)\n",
      "Requirement already satisfied: numpy>=1.20.3 in /root/miniconda3/envs/cube-studio/lib/python3.9/site-packages (from pandas) (1.24.3)\n",
      "Requirement already satisfied: tzdata>=2022.1 in /root/miniconda3/envs/cube-studio/lib/python3.9/site-packages (from pandas) (2023.3)\n",
      "Requirement already satisfied: pytz>=2020.1 in /root/miniconda3/envs/cube-studio/lib/python3.9/site-packages (from pandas) (2023.3)\n",
      "Requirement already satisfied: six>=1.5 in /root/miniconda3/envs/cube-studio/lib/python3.9/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n",
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
      "\u001b[0m"
     ]
    }
   ],
   "source": [
    "!source activate cube-studio && pip install pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "917dfe6dc3d5d6b1",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e18c42e3-660a-40e4-abe7-5ae89e41a194",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from cubestudio.request.model_client import Client,init\n",
    "from cubestudio.train.task import Job_Template,Project,Pipeline,Task,TrainModel\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9f010be3-e690-41d9-94fe-706a607b3302",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "初始化验证成功\n"
     ]
    }
   ],
   "source": [
    "# 初始化客户端\n",
    "HOST = \"http://kubeflow-dashboard.infra/\"\n",
    "token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjdWJlLXN0dWRpbyIsInN1YiI6ImFkbWluIn0.z4XJRqUI4v39MUYDUKdIuQsP5QlRENyVkQIp6a-1fb0'\n",
    "username='admin'\n",
    "init(host=HOST,username=username,token=token)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "447b77c2-41dc-41d8-b3e5-bb0695b31af1",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 注册一个模型\n",
    "trainmodel = Client(TrainModel).add_or_update(\n",
    "    name=f'chatglm3',\n",
    "    version=\"6b\",\n",
    "    describe='chatglm3-6b的预训练模型',\n",
    "    path='/mnt/admin/pipeline/example/sdk/chatglm/chatglm3-6b',\n",
    "    framework=\"transformer\",\n",
    "    api_type=\"vllm\",\n",
    "    project=Client(Project).one(name='public')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "06cbe10e-1984-48d4-a048-1a852e7fdf4e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['chatglm3:6b', 'test:v2024-12-06', 'decision-tree:v2024.12.06.1', 'mnist:v2022.08.01.1', 'resnet50:v2022.08.01.4']\n"
     ]
    }
   ],
   "source": [
    "# 获取模型列表\n",
    "trainmodels = Client(TrainModel).list()\n",
    "trainmodels = [x.name+\":\"+x.version for x in trainmodels]\n",
    "print(trainmodels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3738c96f-78d7-4625-bca3-0dacb0d530a5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "cube-studio",
   "language": "python",
   "name": "cube-studio"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
